; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -msan-track-origins=2 -msan-eager-checks=1 -S -passes=msan 2>&1 | FileCheck %s --implicit-check-not="call void @__msan_"

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!2 = distinct !DISubprogram(name: "t", scope: !3, file: !3, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !6)
!3 = !DIFile(filename: "tmp/noundef.cpp", directory: "/")
!4 = !DISubroutineType(types: !5)
!5 = !{}
!6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
!10 = !DILocation(line: 9, column: 0, scope: !2)
!11 = !DILocation(line: 9, column: 1, scope: !2)
!12 = !DILocation(line: 9, column: 2, scope: !2)
!13 = !DILocation(line: 9, column: 3, scope: !2)

declare void @OneArg(i32 noundef %a) nounwind uwtable sanitize_memory;
declare void @ManyArgs(i32 noundef %a, i32 noundef %b, i32 noundef %c) nounwind uwtable sanitize_memory;

define void @TestOne(ptr noundef %a)  nounwind uwtable sanitize_memory {
; CHECK-LABEL: @TestOne(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    call void @llvm.donothing(), !dbg [[DBG1:![0-9]+]]
; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[A:%.*]], align 4, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[A]] to i64, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP1:%.*]] = xor i64 [[TMP0]], 87960930222080, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP2:%.*]] = inttoptr i64 [[TMP1]] to ptr, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[TMP1]], 17592186044416, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr, !dbg [[DBG1]]
; CHECK-NEXT:    [[_MSLD:%.*]] = load i32, ptr [[TMP2]], align 4, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP4]], align 4, !dbg [[DBG1]]
; CHECK-NEXT:    [[_MSCMP:%.*]] = icmp ne i32 [[_MSLD]], 0, !dbg [[DBG7:![0-9]+]]
; CHECK-NEXT:    br i1 [[_MSCMP]], label [[TMP6:%.*]], label [[TMP7:%.*]], !dbg [[DBG7]], !prof [[PROF8:![0-9]+]]
; CHECK:       6:
; CHECK-NEXT:    call void @__msan_warning_with_origin_noreturn(i32 [[TMP5]]) #[[ATTR3:[0-9]+]], !dbg [[DBG7]]
; CHECK-NEXT:    unreachable, !dbg [[DBG7]]
; CHECK:       7:
; CHECK-NEXT:    call void @OneArg(i32 noundef [[V]]), !dbg [[DBG7]]
; CHECK-NEXT:    ret void
;
entry:
  %v = load i32, ptr %a, !dbg !11
  call void @OneArg(i32 noundef %v), !dbg !10
  ret void
}

define void @TestMany(ptr noundef %a)  nounwind uwtable sanitize_memory {
; CHECK-LABEL: @TestMany(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    call void @llvm.donothing(), !dbg [[DBG1]]
; CHECK-NEXT:    [[X:%.*]] = load i32, ptr [[A:%.*]], align 4, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[A]] to i64, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP1:%.*]] = xor i64 [[TMP0]], 87960930222080, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP2:%.*]] = inttoptr i64 [[TMP1]] to ptr, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[TMP1]], 17592186044416, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr, !dbg [[DBG1]]
; CHECK-NEXT:    [[_MSLD:%.*]] = load i32, ptr [[TMP2]], align 4, !dbg [[DBG1]]
; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP4]], align 4, !dbg [[DBG1]]
; CHECK-NEXT:    [[Y:%.*]] = load i32, ptr [[A]], align 4, !dbg [[DBG9:![0-9]+]]
; CHECK-NEXT:    [[TMP6:%.*]] = ptrtoint ptr [[A]] to i64, !dbg [[DBG9]]
; CHECK-NEXT:    [[TMP7:%.*]] = xor i64 [[TMP6]], 87960930222080, !dbg [[DBG9]]
; CHECK-NEXT:    [[TMP8:%.*]] = inttoptr i64 [[TMP7]] to ptr, !dbg [[DBG9]]
; CHECK-NEXT:    [[TMP9:%.*]] = add i64 [[TMP7]], 17592186044416, !dbg [[DBG9]]
; CHECK-NEXT:    [[TMP10:%.*]] = inttoptr i64 [[TMP9]] to ptr, !dbg [[DBG9]]
; CHECK-NEXT:    [[_MSLD1:%.*]] = load i32, ptr [[TMP8]], align 4, !dbg [[DBG9]]
; CHECK-NEXT:    [[TMP11:%.*]] = load i32, ptr [[TMP10]], align 4, !dbg [[DBG9]]
; CHECK-NEXT:    [[Z:%.*]] = load i32, ptr [[A]], align 4, !dbg [[DBG10:![0-9]+]]
; CHECK-NEXT:    [[TMP12:%.*]] = ptrtoint ptr [[A]] to i64, !dbg [[DBG10]]
; CHECK-NEXT:    [[TMP13:%.*]] = xor i64 [[TMP12]], 87960930222080, !dbg [[DBG10]]
; CHECK-NEXT:    [[TMP14:%.*]] = inttoptr i64 [[TMP13]] to ptr, !dbg [[DBG10]]
; CHECK-NEXT:    [[TMP15:%.*]] = add i64 [[TMP13]], 17592186044416, !dbg [[DBG10]]
; CHECK-NEXT:    [[TMP16:%.*]] = inttoptr i64 [[TMP15]] to ptr, !dbg [[DBG10]]
; CHECK-NEXT:    [[_MSLD2:%.*]] = load i32, ptr [[TMP14]], align 4, !dbg [[DBG10]]
; CHECK-NEXT:    [[TMP17:%.*]] = load i32, ptr [[TMP16]], align 4, !dbg [[DBG10]]
; CHECK-NEXT:    [[_MSCMP:%.*]] = icmp ne i32 [[_MSLD]], 0, !dbg [[DBG7]]
; CHECK-NEXT:    br i1 [[_MSCMP]], label [[TMP18:%.*]], label [[TMP20:%.*]], !dbg [[DBG7]], !prof [[PROF8]]
; CHECK:       18:
; CHECK-NEXT:    [[TMP19:%.*]] = call i32 @__msan_chain_origin(i32 [[TMP5]]), !dbg [[DBG1]]
; CHECK-NEXT:    call void @__msan_warning_with_origin_noreturn(i32 [[TMP19]]) #[[ATTR3]], !dbg [[DBG7]]
; CHECK-NEXT:    unreachable, !dbg [[DBG7]]
; CHECK:       20:
; CHECK-NEXT:    [[_MSCMP3:%.*]] = icmp ne i32 [[_MSLD1]], 0, !dbg [[DBG7]]
; CHECK-NEXT:    br i1 [[_MSCMP3]], label [[TMP21:%.*]], label [[TMP23:%.*]], !dbg [[DBG7]], !prof [[PROF8]]
; CHECK:       21:
; CHECK-NEXT:    [[TMP22:%.*]] = call i32 @__msan_chain_origin(i32 [[TMP11]]), !dbg [[DBG9]]
; CHECK-NEXT:    call void @__msan_warning_with_origin_noreturn(i32 [[TMP22]]) #[[ATTR3]], !dbg [[DBG7]]
; CHECK-NEXT:    unreachable, !dbg [[DBG7]]
; CHECK:       23:
; CHECK-NEXT:    [[_MSCMP4:%.*]] = icmp ne i32 [[_MSLD2]], 0, !dbg [[DBG7]]
; CHECK-NEXT:    br i1 [[_MSCMP4]], label [[TMP24:%.*]], label [[TMP26:%.*]], !dbg [[DBG7]], !prof [[PROF8]]
; CHECK:       24:
; CHECK-NEXT:    [[TMP25:%.*]] = call i32 @__msan_chain_origin(i32 [[TMP17]]), !dbg [[DBG10]]
; CHECK-NEXT:    call void @__msan_warning_with_origin_noreturn(i32 [[TMP25]]) #[[ATTR3]], !dbg [[DBG7]]
; CHECK-NEXT:    unreachable, !dbg [[DBG7]]
; CHECK:       26:
; CHECK-NEXT:    call void @ManyArgs(i32 noundef [[X]], i32 noundef [[Y]], i32 noundef [[Z]]), !dbg [[DBG7]]
; CHECK-NEXT:    ret void
;
entry:
  %x = load i32, ptr %a, !dbg !11
  %y = load i32, ptr %a, !dbg !12
  %z = load i32, ptr %a, !dbg !13
  call void @ManyArgs(i32 noundef %x, i32 noundef %y, i32 noundef %z), !dbg !10
  ret void
}

; CHECK-LABEL: define internal void @msan.module_ctor()
; CHECK:         call void @__msan_init()
